#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QPushButton>
#include<QPainter>
#include"playpage.h"
#include<QMediaPlayer>
#include<QMediaPlaylist>
#include"tips.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setFixedSize(1000,700);//固定窗口大小
    setWindowTitle("Stick Runner");//窗口标题
    setWindowIcon(QIcon(":/image/Image/title.png"));//窗口图像
    QMediaPlayer* player=new QMediaPlayer(this);//播放背景音乐
    QMediaPlaylist* playlist=new QMediaPlaylist;
    playlist->addMedia(QUrl("qrc:/music/Dark_sans - _tale(Ink tale)Ink sans phase3 theme v2.mp3"));
    playlist->setPlaybackMode(QMediaPlaylist::Loop);//循环播放
    player->setVolume(20);//设置音量
    player->setPlaylist(playlist);
    QWidget* play=new playpage;
    connect(ui->startbtn,&QPushButton::clicked,[=](){//点击开始键进入游戏界面并播放背景音乐
        this->hide();
        play->show();
        player->play();
    });
    connect(ui->endbtn,&QPushButton::clicked,this,&QMainWindow::close);//点击关闭游戏键关闭窗口
    QDialog* tip=new tips;
    connect(ui->tipbtn,&QPushButton::clicked,[=](){
        tip->show();
    });
}
void MainWindow::paintEvent(QPaintEvent *){
    QPainter painter(this);
    painter.drawPixmap(0,0,1000,700,QPixmap(":/background/Image/Stickbg.jpg"));//开始页面的背景图
}
MainWindow::~MainWindow()
{
    delete ui;
}
